package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.CollectionAmount;
import com.ruoyi.system.mapper.CollectionAmountMapper;
import com.ruoyi.system.service.CollectionAmountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 馆藏量统计 Service 实现类
 * 具体实现业务逻辑，事务控制等
 *
 * @author [你的名字或团队名]
 */
@Service
public class CollectionAmountServiceImpl implements CollectionAmountService {

    @Autowired
    private CollectionAmountMapper collectionAmountMapper;

    @Override
    public List<CollectionAmount> selectCollectionAmountList(CollectionAmount collectionAmount) {
        return collectionAmountMapper.selectCollectionAmountList(collectionAmount);
    }

    @Override
    public CollectionAmount selectCollectionAmountById(Long id) {
        return collectionAmountMapper.selectCollectionAmountById(id);
    }

    @Override
    public int insertCollectionAmount(CollectionAmount collectionAmount) {
        return collectionAmountMapper.insertCollectionAmount(collectionAmount);
    }

    @Override
    public int updateCollectionAmount(CollectionAmount collectionAmount) {
        return collectionAmountMapper.updateCollectionAmount(collectionAmount);
    }

    @Override
    public int deleteCollectionAmountById(Long id) {
        return collectionAmountMapper.deleteCollectionAmountById(id);
    }

    @Override
    public int deleteCollectionAmountByIds(Long[] ids) {
        return collectionAmountMapper.deleteCollectionAmountByIds(ids);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int batchSaveCollectionAmount(List<CollectionAmount> list) {
        if (list.isEmpty()) {
            return 0; // 空列表，无需操作
        }
        // 1. 删除指定年份的旧数据
        collectionAmountMapper.deleteAll();
        // 2. 批量插入新数据
        return collectionAmountMapper.batchInsertCollectionAmount(list);
    }
}